import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/bottom_tab_controller.dart';

class BottomTabView extends GetView<BottomTabController> {
  const BottomTabView({super.key});

  @override
  Widget build(BuildContext context) {
    // return Scaffold(
    //   body: Column(
    //     children: [
    //       // Obx(() => setupPageView()),
    //       // HomeView(Get.arguments),
    //     ],
    //   ),
    //   bottomNavigationBar: setupBottomBar(),
    // );
    return setupPageView();
  }

  Widget setupPageView() {
    return PageView(
      controller: controller.pageController,
      physics: const NeverScrollableScrollPhysics(), // 禁止左右滑动
      children: controller.pages,
      onPageChanged: (index) {
        controller.setCurrentIndex(index);
      },
    );
  }

  Widget setupBottomBar() {
    return Container(
      height: 83,
      decoration: const BoxDecoration(
        border: Border(
          top: BorderSide(color: Colors.grey, width: 0.3), // 细线颜色和宽度
        ),
      ),
      child: BottomNavigationBar(
        fixedColor: Colors.red, // 选中的颜色
        currentIndex: controller.currentIndex.value, //第几个菜单选中
        type: BottomNavigationBarType.fixed, //如果底部有4个或者4个以上的菜单的时候就需要配置这个参数
        onTap: (index) {
          controller.setCurrentIndex(index);
          controller.pageController.jumpToPage(index);
        },
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "购物车"),
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "我的"),
        ]
      ),
    );
  }
}
